<?php
/*
 * Gallery - a web based photo album viewer and editor
 * Copyright (C) 2000-2002 Bharat Mediratta
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

// Hack prevention.
if (!empty($_REQUEST["GALLERY_BASEDIR"])) {
	print "Security violation\n";
	exit;
	}

require_once('./init.php'); 
$myts =& MyTextSanitizer::getInstance();
 
// Hack check
if (!$gallery->user->canChangeTextOfAlbum($gallery->album)) {
	exit;
}

$err = "";
if (isset($submit) && !strcmp($submit, "Save")) {
	if (($capture_year < 3000) && ($capture_year > 1000)) { // only allow photo capture dates from 1000 to 3000.
		$gallery->album->setCaption($index, $myts->addSlashes($data));
		$gallery->album->setKeywords($index, $myts->addSlashes($keywords));
		$dateArray["year"] = $capture_year;	
		$dateArray["mon"] = $capture_mon;
		$dateArray["mday"] = $capture_mday;
		$dateArray["hours"] = $capture_hours;
		$dateArray["minutes"] = $capture_minutes;
		$dateArray["seconds"] = $capture_seconds;
		$gallery->album->setItemCaptureDate($index, $dateArray );
		$gallery->album->save();
		dismissAndReload();
		if (!isDebugging()) {
			return;
		}
	} else {
		$err = _ERROR_YEAR_LIMIT;
	}
}
?>
<html>
<head>
  <title><?php echo _XG_EDIT_CAPTION; ?></title>
  <?php echo getStyleSheetLink() ?>
</head>
<body>

<center>
<?php echo _XG_ENTER_CAPTION; ?>
<br><br>
<?php 	echo $gallery->album->getThumbnailTag($index) ?>
<?php		echo makeFormIntro("edit_caption.php", 
			array("name" => "theform", 
				"method" => "POST")); ?>
<input type="hidden" name="index" value="<?php echo $index ?>">
<textarea name="data" rows="5" cols="40"><?php echo $myts->stripSlashesGPC($gallery->album->getCaption($index)) ?></textarea>
<br><br>
<?php echo _XG_ENTER_KEYWORD_PHOTO; ?>
<br><br>
<textarea name="keywords" rows=1 cols=40><?php echo $myts->stripSlashesGPC($gallery->album->getKeywords($index)) ?></textarea>

<br>

<?php
// get the itemCaptureDate
echo "<span class=error>$err</span><br><br>";
$itemCaptureDate = $gallery->album->getItemCaptureDate($index);

$hours = $itemCaptureDate["hours"];
$minutes = $itemCaptureDate["minutes"];
$seconds = $itemCaptureDate["seconds"];
$mon = $itemCaptureDate["mon"];
$mday = $itemCaptureDate["mday"];
$year = $itemCaptureDate["year"];
// start capture date table
?>
<table border=0>
  <tr>
    <td colspan="6" align="center"><?php echo _XG_PHOTO_CAPTURE_DATE; ?></td>
  </tr>
  <tr>
    <td><?php echo _XG_MONTH; ?></td>
    <td><?php echo _XG_DAY; ?></td>
    <td><?php echo _XG_YEAR; ?></td>
    <td><?php echo _XG_HOURS; ?></td>
    <td><?php echo _XG_MINUTES; ?></td>
    <td><?php echo _XG_SECONDS; ?></td>
  </tr>
  <tr>
<?php
// start making drop downs
echo "<td>";
echo drawSelect("capture_mon", padded_range_array(1, 12), $mon, 1);
echo "</td>";

echo "<td>";
echo drawSelect("capture_mday", padded_range_array(1, 31), $mday, 1);
echo "</td>";

echo "<td>";
echo "<input type=text name=\"capture_year\" value=\"$year\" size=\"4\">";
echo "</td>";

echo "<td>";
echo drawSelect("capture_hours", padded_range_array(0, 23), $hours, 1);
echo "</td>";

echo "<td>";
echo drawSelect("capture_minutes", padded_range_array(0, 59), $minutes, 1);
echo "</td>";

echo "<td>";
echo drawSelect("capture_seconds", padded_range_array(0, 59), $seconds, 1);
echo "</td>";
?>
  </tr>
</table>
<br><br>
<input type="submit" name="submit" value="<?php echo _XG_SAVE; ?>">
<input type="submit" name="submit" value="<?php echo _XG_CANCEL; ?>" onclick='parent.close()'>


</form>

<script language="javascript1.2">
<!--   
// position cursor in top form field
document.theform.data.focus();
//-->
</script>

</body>
</html>
